using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using MuseumsBC.Models;
using Android.GoogleMaps;

namespace MuseumsBC.Activities
{
    [Activity(Label = "Museum Location")]
    public class MuseumDetailMapActivity : MapActivity
    {
        private Museum _Museum { get; set; }
        private GeoPoint MuseumLocation
        {
            get
            {
                int latE6 = (int)(_Museum.Latitude * 1e6);
                int lonE6 = (int)(_Museum.Longitude * 1e6);
                return new GeoPoint(latE6, lonE6);
            }
        }

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            _Museum = setMuseum();
            SetContentView(Resource.Layout.MuseumDetailMap);

            var mapView = FindViewById<MapView>(Resource.MuseumDetailMap.Map);

            mapView.Controller.AnimateTo(MuseumLocation);
            mapView.Controller.SetZoom(10);

            var x = new AlertDialog.Builder(this);
            x.SetMessage(string.Format("museumLocation: {0} {1}", MuseumLocation.LatitudeE6, MuseumLocation.LongitudeE6));
            x.SetNegativeButton("XXX", (sender, args) =>
                {
                    Toast
                         .MakeText(this, "Clicked cancel", ToastLength.Short)
                         .Show();
                    //this.Finish();
                });
            x.Show();



            //var tv = FindViewById<TextView>(Resource.MuseumDetailMap.Placeholder);
            //tv.Text = string.Format("FILLER HERE WAITING ON MAP CONTROL. MUSEUM = {0}", _Museum.MuseumName);

        }

        protected override bool IsRouteDisplayed
        {
            get { return false; }
        }

        private Museum setMuseum()
        {
            int outNum;
            int museumId = int.TryParse(Intent.GetStringExtra("MuseumId"), out outNum) ? outNum : -1;

            return ((MuseumsBCApplication)Application).MuseumRepository.GetMuseumById(museumId);
        }
    }
}
